package xzit.gcxy.xxhzx.zhh.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import xzit.gcxy.xxhzx.zhh.common.Pagination;
import xzit.gcxy.xxhzx.zhh.dao.BaseDao;
import xzit.gcxy.xxhzx.zhh.entity.TeacherInfoVO;
import xzit.gcxy.xxhzx.zhh.service.TeacherService;
import xzit.gcxy.xxhzx.zhh.util.InstituteUtil;

@Service("teacherService")
public class TeacherServiceImpl extends SystemServiceImpl implements TeacherService {
	
	@Autowired
	private BaseDao baseDao;
	
	public Pagination<TeacherInfoVO> findPageData(DetachedCriteria condition,
			TeacherInfoVO ce, int page, int rows) {
		Pagination<TeacherInfoVO> pagination = new Pagination<TeacherInfoVO>(page, rows);
		condition.createAlias("institute", "in");
		condition.add(Restrictions.eq("in.instituteid", InstituteUtil.getCurrentInstituteId()));
		if(ce.getGonghao() != null && !"".equals(ce.getGonghao())){
			condition.add(Restrictions.like("gonghao", "%"+ce.getGonghao()+"%"));
		}
		if(ce.getRealname() != null && !"".equals(ce.getRealname())){
			condition.add(Restrictions.like("realname", "%"+ce.getRealname()+"%"));
		}
		condition.addOrder(Order.asc("gonghao"));
		int total = this.baseDao.getRowCountByDetachedCriteria(condition);
		pagination.setTotalCount(total);
		condition.setProjection(null);
		if (total != 0) {
			List<TeacherInfoVO> datas = baseDao.findByDetachedCriteria(condition, page, rows);
			pagination.setDatas(datas);
		}
		return pagination;
	}

}
